<!--------------------------------
 - @Author: Ronnie Zhang
 - @LastEditor: Ronnie Zhang
 - @LastEditTime: 2023/12/05 21:30:11
 - @Email: zclzone@outlook.com
 - Copyright © 2023 Ronnie Zhang(大脸怪) | https://isme.top
 --------------------------------->

<template>
  <AppPage show-footer>
    <n-card class="min-w-200 w-50%" hoverable title="公司信息">
      <template #footer>
        <n-switch v-model:value="updateDisabled" />
        <n-button type="primary" @click="updateConfigModel">
          确定
        </n-button>
      </template>
      <n-form
        :model="configModel" :rules="rules" :disabled="updateDisabled" label-placement="left" label-width="auto"
        require-mark-placement="right-hanging"
      >
        <n-form-item label="公司名称" path="appName">
          <n-input v-model:value="configModel.appName" placeholder="Input" />
        </n-form-item>
        <n-form-item label="电话" path="phone">
          <n-input v-model:value="configModel.phone" placeholder="Input" />
        </n-form-item>
        <n-form-item label="地址" path="address">
          <n-input v-model:value="configModel.address" placeholder="Textarea" type="textarea" />
        </n-form-item>
        <n-form-item label="经纬度" :show-feedback="false">
          <n-grid :cols="2">
            <n-form-item-gi path="longitude">
              <n-input v-model:value="configModel.longitude" placeholder="Nested Path 1" />
            </n-form-item-gi>
            <n-form-item-gi path="latitude">
              <n-input v-model:value="configModel.latitude" placeholder="Nested Path 1" />
            </n-form-item-gi>
          </n-grid>
        </n-form-item>
        <n-form-item label="默认运费" path="defaultFreight">
          <n-input v-model:value="configModel.defaultFreight" placeholder="Input" />
        </n-form-item>
        <n-form-item label="默认折扣" path="defaultDiscount">
          <n-input v-model:value="configModel.defaultDiscount" placeholder="Input" />
        </n-form-item>
        <n-form-item label="营业时间" path="inputValue">
          <n-time-picker v-model:formatted-value="configModel.openHourStart" value-format="HH:mm:ss" />至
          <n-time-picker v-model:formatted-value="configModel.openHourEnd" value-format="HH:mm:ss" />
        </n-form-item>
        <n-form-item label="公司简介" path="inputValue">
          <n-checkbox-group v-model:value="configModel.saleTypeList">
            <n-space>
              <n-checkbox value="1">
                堂食
              </n-checkbox>
              <n-checkbox value="2">
                外卖
              </n-checkbox>
              <n-checkbox value="3">
                自提
              </n-checkbox>
            </n-space>
          </n-checkbox-group>
        </n-form-item>
      </n-form>
    </n-card>
  </AppPage>
</template>

<script setup>
import apiGlobal from '@/api'

defineOptions({ name: 'WxappConfig' })
const updateDisabled = ref(true)
const configModel = ref({})
onMounted(async () => {
  configModel.value = await apiGlobal.getAppConfig({ id: 1 })
})
async function updateConfigModel() {
  await apiGlobal.updateAppConfig(configModel.value)
}
</script>
